package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.component.util.CommonUtil;
import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.model.dao.console.MagicBoxDO;
import com.qumitech.visualnovel.pubdef.dto.poundmagicbox.MagicBoxQueryDTO;
import com.qumitech.visualnovel.pubdef.dto.poundmagicbox.UserPoundBoxStatisticAdminQueryDTO;
import com.qumitech.visualnovel.service.magicbox.MagicBoxService;
import com.google.common.collect.ImmutableMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ywxie
 * @date 2019/12/25 10:02
 * @description
 */
@RestController
@RequestMapping("/api/magicbox")
public class MagicBoxController {

    @Autowired
    private MagicBoxService magicBoxService;

    @RequestMapping(value = "/record/detail/list", method = RequestMethod.GET)
    public BaseRsp listDetail(MagicBoxQueryDTO queryDTO){
        String[] stringTime = CommonUtil.setStartTime(queryDTO.getStartTime(), queryDTO.getEndTime());
        queryDTO.setStartTime(stringTime[0]);
        queryDTO.setEndTime(stringTime[1]);
        queryDTO.setTableNames(CommonUtil.getTableListFromDate(stringTime[0], stringTime[1], "magic_box"));
        Integer count = magicBoxService.countMagicBox(queryDTO);
        List<MagicBoxDO> magicBoxDOList = magicBoxService.listMagicBox(queryDTO);
        return new BaseRsp(ResultEnum.SUCCESS, ImmutableMap.of("count", count, "magic_box", magicBoxDOList));
    }

    @GetMapping("/statistic/list")
    public BaseRsp magicBoxStatisticList(UserPoundBoxStatisticAdminQueryDTO queryDTO) {
        return new BaseRsp(ResultEnum.SUCCESS, ImmutableMap.of("user_pound_statistic",
                magicBoxService.listPoundMagicBoxStatistic(queryDTO),
                "count", magicBoxService.countPoundMagicBoxStatistic(queryDTO)));
    }
}
